package com.hiwhitley.himei.module.game;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.hiwhitley.himei.R;
import com.hiwhitley.himei.app.base.BaseActivity;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.GSYVideoPlayer;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import butterknife.BindView;

/**
 * Created by hiwhitley on 17-2-17.
 */

public class CommonPlayActivity extends BaseActivity {

    @BindView(R.id.video_player)
    StandardGSYVideoPlayer videoPlayer;

    public static final String TAG_VIDEO_URL = "video_url";
    public static final String TAG_GAME_NAME = "game_name";
    public static String videoUrl ;
    public static String gameName ;

    public static Intent newIntent(Context context, String gameName, String url) {
        Intent intent = new Intent(context, CommonPlayActivity.class);
        intent.putExtra(TAG_VIDEO_URL, url);
        intent.putExtra(TAG_GAME_NAME, gameName);
        return intent;
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_common_play;
    }

    @Override
    protected void init() {
        videoUrl = getIntent().getStringExtra(TAG_VIDEO_URL);
        gameName = getIntent().getStringExtra(TAG_GAME_NAME);
    }

    @Override
    protected void setListeners() {
        prepareVideoView();
    }

    private void prepareVideoView() {

        videoPlayer.setUp(videoUrl, true, gameName);
        videoPlayer.startPlayLogic();
        videoPlayer.getBackButton().setVisibility(View.VISIBLE);
        videoPlayer.getBackButton().setOnClickListener(v -> {
            onBackPressed();
        });

        videoPlayer.getFullscreenButton().setVisibility(View.GONE);

    }


    @Override
    public void onBackPressed() {
        if (StandardGSYVideoPlayer.backFromWindowFull(this)) {
            return;
        }
        super.onBackPressed();
    }

    @Override
    protected void onPause() {
        super.onPause();
        GSYVideoManager.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        GSYVideoManager.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        GSYVideoPlayer.releaseAllVideos();
    }
}
